﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zero.Core;
using Zero.Core.Extensions;

namespace Zero.Data
{
    public class BaseEntity
    {
        public string CreateUserID { get; set; }
        public Nullable<System.DateTime> CreateDate { get; set; }
        public string ModifyUserID { get; set; }
        public Nullable<System.DateTime> ModifyDate { get; set; }
        public bool IsDel { get; set; }
        public bool IsEnable { get; set; }
        public int OrderIndex { get; set; }
        public void Load(NameValueCollection coll)
        {
            if (true)
            {
                if (coll == null) return;
                foreach (var key in coll.AllKeys)
                {
                    var prop = this.GetType().GetProperty(key);
                    if (prop != null)
                    {
                        if (coll[key].HasValue())
                        {
                            var propValue = DataHelper.ConvertValue(prop.PropertyType, coll[key]);
                            prop.SetValue(this, propValue, null);
                        }
                        else if (prop.PropertyType == typeof(string))
                        {
                            prop.SetValue(this, null, null);
                        }

                    }
                }
                
            }
        }
    }
}
